package com.wd.jetpack.demo.paging

import android.view.View
import androidx.lifecycle.Observer
import androidx.paging.PagedList
import androidx.recyclerview.widget.LinearLayoutManager
import com.wd.jetpack.R
import com.wd.jetpack.base.BaseActivity
import com.wd.jetpack.databinding.ActivityDemoPagingBinding
import com.wd.jetpack.demo.paging.adapter.MoviePagedListAdapter
import com.wd.jetpack.demo.paging.model.Movie
import com.wd.jetpack.demo.paging.vm.DemoPagingViewModel
import com.wd.jetpack.util.SimpleDividerDecoration

/**
 * NA<BR>
 *
 * @author W4255
 * @version [V0.0.1, 2021/6/29]
 * @Description: NA
 */
class DemoPagingActivity : BaseActivity<ActivityDemoPagingBinding>() {
    private val viewModel: DemoPagingViewModel by lazy { DemoPagingViewModel() }
    private val pagedListAdapter: MoviePagedListAdapter by lazy { MoviePagedListAdapter() }

    override fun getLayoutId(): Int {
        return R.layout.activity_demo_paging
    }

    override fun initView() {
        mBinding.rvView.adapter = pagedListAdapter;
        mBinding.rvView.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
        mBinding.rvView.addItemDecoration(SimpleDividerDecoration(this))
    }

    override fun initData() {
        viewModel.moviePagedList.observe(this, Observer { movies: PagedList<Movie?>? ->
            pagedListAdapter.submitList(movies)
        })
    }

    override fun onClick(v: View) {
    }
}